package com.jagochan.imchat.module.wx.handler;

import com.jagochan.imchat.module.wx.service.WxMsgService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 扫码事件由该handler处理
 */
@Component
@Slf4j
public class ScanHandler extends AbstractHandler {

    @Resource
    private WxMsgService wxMsgService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage,
                                    Map<String, Object> map,
                                    WxMpService wxMpService,
                                    WxSessionManager wxSessionManager) throws WxErrorException {
        log.info("\n【ScanHandler】用户扫码：\nopenId = {} \n场景值 = {}", wxMpXmlMessage.getFromUser(), wxMpXmlMessage.getEventKey());

        return wxMsgService.scan(wxMpXmlMessage, wxMpService);
    }

}
